package util

import (
	"regexp"
	"strconv"
	"strings"
)

// 字符串转换为 float64
func StrToFloat(str string) (float64, error) {
	f, err := strconv.ParseFloat(str, 64)
	if err != nil {
		return 0, err
	}
	return f, nil
}

// float64转换为字符串
func FloatToStr(f float64) string {
	str := strconv.FormatFloat(f, 'f', -1, 64)
	return str
}

// 字符串转换为 uint
func StrToUint(str string) uint {
	u, err := strconv.ParseUint(str, 10, 32)
	if err != nil {
		return 0
	}
	return uint(u)
}

func StrTirm(money string) string {
	re := regexp.MustCompile(`[\s\n]+`)
	str := re.ReplaceAllString(money, "")
	result := strings.ReplaceAll(str, "\u0000", "")
	return result
}
